package pilebis;

import java.util.ArrayList;

public class Variable {

	public Classe type;
	public String name;
	//public String valeur;
	public ArrayList<Variable> attributs;
	public ArrayList<Poignee> poignees;
	public int xaff;
	public int yaff;
	
	public Variable(Classe type, String name){
		this.type = type;
		this.name = name;
		//this.valeur = null;
		this.attributs = new ArrayList<Variable>();
		this.poignees = new ArrayList<Poignee>();
		if(!this.type.isPrimitive){
			this.createAttributs();
		}
	}
	
	/*
	public Variable(Classe type, String name, String valeur){
		this.type = type;
		this.name = name;
		this.valeur = valeur;
		this.attributs = new ArrayList<Variable>();
		this.poignees = new ArrayList<Poignee>();
	}
	*/
	
	public void createAttributs(){
		for(int k=0; k<this.type.typesAttributs.size(); k++){
			this.attributs.add(new Variable(this.type.typesAttributs.get(k), 
					this.name +"."+ this.type.nomsAttributs.get(k)));
		}
	}
	
	public void retirePoignee(String namepgn){
		int k = 0;
		boolean found = false;
		while((k<poignees.size())&&(!found)){
			if(poignees.get(k).nom.equals(namepgn)){
				poignees.remove(k);
				found = true;
			}
			k++;
		}
	}	
}